from pydantic import BaseModel, Field
from typing import Optional


class TagBase(BaseModel):
    """标签基础模型"""
    name: str = Field(..., min_length=1, max_length=50)
    color: str = Field(default="#409EFF", pattern=r'^#[0-9A-Fa-f]{6}$')


class TagCreate(TagBase):
    """标签创建模型"""
    pass


class TagUpdate(BaseModel):
    """标签更新模型"""
    name: Optional[str] = Field(None, min_length=1, max_length=50)
    color: Optional[str] = Field(None, pattern=r'^#[0-9A-Fa-f]{6}$')


class TagResponse(TagBase):
    """标签响应模型"""
    id: int
    user_id: int
    
    class Config:
        from_attributes = True

